建立會員登入欄位
public class MemberLoginView
{
[Display(Name ="會員帳號")]
[Required(ErrorMessage ="請輸入會員帳號")]
public string UserName { get; set; }
[Display(Name = "會員密碼")]
[Required(ErrorMessage = "請輸入會員密碼")]
public string Password { get; set; }
}
建立Member資料表驗證欄位
[MetadataType(typeof(MemberMetadata))]
public partial class Member
{
private class MemberMetadata
{
[Display(Name ="帳號")]
[Required(ErrorMessage ="請輸入帳號")]
[StringLength(30,MinimumLength=6,ErrorMessage ="帳號長度需6~30字元")]
public string Account { get; set; }
public string Password { get; set; }
[Display(Name ="姓名")]
[StringLength(20,ErrorMessage ="姓名長度最多為20字元")]
[Required(ErrorMessage ="請輸入姓名")]
public string Name { get; set; }
[Display(Name ="Email")]
[Required(ErrorMessage ="請輸入Email")]
[EmailAddress(ErrorMessage ="這不是Email格式")]
public string Email { get; set; }
public string AuthCode { get; set; }
public string IsAdmin { get; set; }
}
}
建立會員註冊欄位驗證
public class MemberRegisterView
{
public Member newMember { get; set; }
[Display(Name ="密碼")]
[Required(ErrorMessage ="請輸入密碼")]
public string Password { get; set; }
[Display(Name ="確認密碼")]
[Compare("Password",ErrorMessage ="密碼輸入不一致")]
[Required(ErrorMessage ="請輸入確認密碼")]
public string PasswordCheck { get; set; }
}
建立會員修改密碼的欄位驗證
public class MemberChangePasswordView
{
[Display(Name ="舊密碼")]
[Required(ErrorMessage ="請輸入密碼")]
public string Password { get; set; }
[Display(Name ="新密碼")]
[Required(ErrorMessage ="請輸入密碼")]
public string NewPassword { get; set; }
[Display(Name ="新密碼確認")]
[Required(ErrorMessage ="請輸入密碼")]
[Compare("NewPassword",ErrorMessage ="兩次密碼不一致")]
public string NewPasswordCheck { get; set; }
}